<?php
class classArticleService{
    public function getArticleName($iID){
        if(trim($iID)=='' or !is_numeric($iID) or $iID<1) return '';

        $sql_result = mysql_query('SELECT SC_Caption FROM top_menu_sub_category  WHERE ID='.$iID);
        $sql_obj = mysql_fetch_object($sql_result);

        return $sql_obj->SC_Caption;
    }

    public function getTopCategoryNameOfArticle($iID){
        if(trim($iID)=='' or !is_numeric($iID) or $iID<1) return '';

        $sql_result = mysql_query('
            SELECT TC_Caption
            FROM top_menu_sub_category, top_menu_top_category
            WHERE
                top_menu_sub_category.ID='.$iID.' AND
                top_menu_sub_category.TC_ID=top_menu_top_category.ID
        ');
        $sql_obj = mysql_fetch_object($sql_result);

        return $sql_obj->TC_Caption;
    }

    public function getNewsName($iID){
        if(trim($iID)=='' or !is_numeric($iID) or $iID<1) return '';

        $sql_result = mysql_query('SELECT News_Caption FROM top_menu_news WHERE ID='.$iID);
        $sql_obj = mysql_fetch_object($sql_result);
        
        return $sql_obj->News_Caption;
    }

    public function getCategoryAndArticleName(){
        $_URL 	= new classURL();
		$iType	= $_URL->GetValueFromURL($_URL->GetMenu(), 'a_type');
        $iTextID= $_URL->GetValueFromURL($_URL->GetMenu(), 'a_text');

        if ($iType==1){
            return ' - '.self::getNewsName($iTextID);
        }
        if ($iType==2){
            return ' - '.self::getTopCategoryNameOfArticle($iTextID).' - '.self::getArticleName($iTextID);
        }
    }

    public function newsExists($iNID){
        if((trim($iNID)=='') or !is_numeric($iNID) or ($iNID<1)) return false;
        $sql_result = mysql_query('SELECT COUNT(*) FROM top_menu_news WHERE ID='.$iNID);
        $sql_row = mysql_fetch_row($sql_result);
        if($sql_row[0]>0) return true; else return false;
    }

    public function articleExists($iAID){
        if((trim($iAID)=='') or !is_numeric($iAID) or ($iAID<1)) return false;
        $sql_result = mysql_query('SELECT COUNT(*) FROM top_menu_sub_category  WHERE ID='.$iAID);
        $sql_row = mysql_fetch_row($sql_result);
        if($sql_row[0]>0) return true; else return false;
    }
}
?>
